// 
//  Author:
//    Snowdrop Short snowdrop dot short at gmail dot com
// 
//  Copyright (c) 2009, Snowdrop Short
// 
//  All rights reserved.
// 
//  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// 
//     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
//       the documentation and/or other materials provided with the distribution.
//     * Neither the name of the [ORGANIZATION] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
// 
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
//  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// 

using System;
using log4net;
namespace OpenFuse.Backend
{
	
	
	public class SessionLogger : ILog
	{

		SlSession _session;
		ILog _logger;

		private string _preamble;
		
		public SessionLogger(SlSession session, ILog logger)
		{
			_session = session;
			_logger = logger;
			
			_preamble = string.Format("[{0}:{1} {2}]", _session.GridName, _session.FirstName, _session.LastName);
		}
		
		#region ILog implementation

		public void Debug(object message)
		{
			if(_logger.IsDebugEnabled)
			{
				_logger.DebugFormat("{0} {1}", _preamble, message);
			}
		}
		
		public void Debug(object message, Exception exception)
		{
			if(_logger.IsDebugEnabled)
			{
				_logger.Debug(string.Format("{0}", message), exception);
			}
		}
		
		public void DebugFormat(string format, params object[] args)
		{
			if(_logger.IsDebugEnabled)
			{
				_logger.DebugFormat("{0} {1}", _preamble, string.Format(format, args));
			}
		}
		
		public void DebugFormat(string format, object arg0)
		{
			if(_logger.IsDebugEnabled)
			{
				_logger.DebugFormat("{0} {1}", _preamble, string.Format(format, arg0));
			}
		}
		
		public void DebugFormat(string format, object arg0, object arg1)
		{
			if(_logger.IsDebugEnabled)
			{
				_logger.DebugFormat("{0} {1}", _preamble, string.Format(format, arg0, arg1));
			}
		}
		
		public void DebugFormat(string format, object arg0, object arg1, object arg2)
		{
			if(_logger.IsDebugEnabled)
			{
				_logger.DebugFormat("{0} {1}", _preamble, string.Format(format, arg0, arg1, arg2));
			}
		}
		
		public void DebugFormat(IFormatProvider provider, string format, params object[] args)
		{
			if(_logger.IsDebugEnabled)
			{
				_logger.DebugFormat(provider, "{0} {1}", _preamble, string.Format(format, args));
			}
		}

		public void Info(object message)
		{
			if(_logger.IsInfoEnabled)
			{
				_logger.InfoFormat("{0} {1}", _preamble, message);
			}
		}
		
		public void Info(object message, Exception exception)
		{
			if(_logger.IsInfoEnabled)
			{
				_logger.Info(string.Format("{0}", message), exception);
			}
		}
		
		public void InfoFormat(string format, params object[] args)
		{
			if(_logger.IsInfoEnabled)
			{
				_logger.InfoFormat("{0} {1}", _preamble, string.Format(format, args));
			}
		}
		
		public void InfoFormat(string format, object arg0)
		{
			if(_logger.IsInfoEnabled)
			{
				_logger.InfoFormat("{0} {1}", _preamble, string.Format(format, arg0));
			}
		}
		
		public void InfoFormat(string format, object arg0, object arg1)
		{
			if(_logger.IsInfoEnabled)
			{
				_logger.InfoFormat("{0} {1}", _preamble, string.Format(format, arg0, arg1));
			}
		}
		
		public void InfoFormat(string format, object arg0, object arg1, object arg2)
		{
			if(_logger.IsInfoEnabled)
			{
				_logger.InfoFormat("{0} {1}", _preamble, string.Format(format, arg0, arg1, arg2));
			}
		}
		
		public void InfoFormat(IFormatProvider provider, string format, params object[] args)
		{
			if(_logger.IsInfoEnabled)
			{
				_logger.DebugFormat(provider, "{0} {1}", _preamble, string.Format(format, args));
			}
		}

		public void Warn(object message)
		{
			if(_logger.IsWarnEnabled)
			{
				_logger.WarnFormat("{0} {1}", _preamble, message);
			}
		}
		
		public void Warn(object message, Exception exception)
		{
			if(_logger.IsWarnEnabled)
			{
				_logger.Warn(string.Format("{0", message), exception);
			}
		}
		
		public void WarnFormat(string format, params object[] args)
		{
			if(_logger.IsWarnEnabled)
			{
				_logger.WarnFormat("{0} {1}", _preamble, string.Format(format, args));
			}
		}
		
		public void WarnFormat(string format, object arg0)
		{
			if(_logger.IsWarnEnabled)
			{
				_logger.WarnFormat("{0} {1}", _preamble, string.Format(format, arg0));
			}
		}
		
		public void WarnFormat(string format, object arg0, object arg1)
		{
			if(_logger.IsWarnEnabled)
			{
				_logger.WarnFormat("{0} {1}", _preamble, string.Format(format, arg0, arg1));
			}
		}
		
		public void WarnFormat(string format, object arg0, object arg1, object arg2)
		{
			if(_logger.IsWarnEnabled)
			{
				_logger.WarnFormat("{0} {1}", _preamble, string.Format(format, arg0, arg1, arg2));
			}
		}
		
		public void WarnFormat(IFormatProvider provider, string format, params object[] args)
		{
			if(_logger.IsWarnEnabled)
			{
				_logger.DebugFormat(provider, "{0} {1}", _preamble, string.Format(format, args));
			}
		}
		
		public void Error(object message)
		{
			if(_logger.IsErrorEnabled)
			{
				_logger.ErrorFormat("{0} {1}", _preamble, message);
			}
		}
		
		public void Error(object message, Exception exception)
		{
			if(_logger.IsErrorEnabled)
			{
				_logger.Error(string.Format("{0}", message), exception);
			}
		}
		
		public void ErrorFormat(string format, params object[] args)
		{
			if(_logger.IsErrorEnabled)
			{
				_logger.ErrorFormat("{0} {1}", _preamble, string.Format(format, args));
			}
		}
		
		public void ErrorFormat(string format, object arg0)
		{
			if(_logger.IsErrorEnabled)
			{
				_logger.ErrorFormat("{0} {1}", _preamble, string.Format(format, arg0));
			}
		}
		
		public void ErrorFormat(string format, object arg0, object arg1)
		{
			if(_logger.IsErrorEnabled)
			{
				_logger.ErrorFormat("{0} {1}", _preamble, string.Format(format, arg0, arg1));
			}
		}
		
		public void ErrorFormat(string format, object arg0, object arg1, object arg2)
		{
			if(_logger.IsErrorEnabled)
			{
				_logger.ErrorFormat("{0} {1}", _preamble, string.Format(format, arg0, arg1, arg2));
			}
		}
		
		public void ErrorFormat(IFormatProvider provider, string format, params object[] args)
		{
			if(_logger.IsErrorEnabled)
			{
				_logger.DebugFormat(provider, "{0} {1}", _preamble, string.Format(format, args));
			}
		}
		
		public void Fatal(object message)
		{
			if(_logger.IsFatalEnabled)
			{
				_logger.FatalFormat("{0} {1}", _preamble, message);
			}
		}
		
		public void Fatal(object message, Exception exception)
		{
			if(_logger.IsFatalEnabled)
			{
				_logger.Fatal(string.Format("{0} {1}", message), exception);
			}
		}
		
		public void FatalFormat(string format, params object[] args)
		{
			if(_logger.IsFatalEnabled)
			{
				_logger.FatalFormat("{0} {1}", _preamble, string.Format(format, args));
			}
		}
		
		public void FatalFormat(string format, object arg0)
		{
			if(_logger.IsFatalEnabled)
			{
				_logger.FatalFormat("{0} {1}", _preamble, string.Format(format, arg0));
			}
		}
		
		public void FatalFormat(string format, object arg0, object arg1)
		{
			if(_logger.IsFatalEnabled)
			{
				_logger.FatalFormat("{0} {1}", _preamble, string.Format(format, arg0, arg1));
			}
		}
		
		public void FatalFormat(string format, object arg0, object arg1, object arg2)
		{
			if(_logger.IsFatalEnabled)
			{
				_logger.FatalFormat("{0} {1}", _preamble, string.Format(format, arg0, arg1, arg2));
			}
		}
		
		public void FatalFormat(IFormatProvider provider, string format, params object[] args)
		{
			if(_logger.IsFatalEnabled)
			{
				_logger.DebugFormat(provider, "{0} {1}", _preamble, string.Format(format, args));
			}
		}
		
		
		public bool IsDebugEnabled {
			get {
				return _logger.IsDebugEnabled;
			}
		}
		
		public bool IsInfoEnabled {
			get {
				return _logger.IsInfoEnabled;
			}
		}
		
		public bool IsWarnEnabled {
			get {
				return _logger.IsWarnEnabled;
			}
		}
		
		public bool IsErrorEnabled {
			get {
				return _logger.IsErrorEnabled;
			}
		}
		
		public bool IsFatalEnabled {
			get {
				return _logger.IsFatalEnabled;
			}
		}
		#endregion
		
		public SessionLogger()
		{
		}
	
		#region ILoggerWrapper implementation
		public log4net.Core.ILogger Logger {
			get {
				throw new System.NotImplementedException();
			}
		}
		#endregion
}
}
